/**
 * 异步加载js文件
 * @param src js文件地址
 */
export async function loadScript(src: string) {
  return new Promise<boolean>(resolve => {
    const scriptElement = document.createElement('script');
    scriptElement.src = src;
    scriptElement.addEventListener('load', () => resolve(true));
    scriptElement.addEventListener('error', () => resolve(false));
    document.body.append(scriptElement);
  });
}

/**
 * 异步加载css文件
 * @param src css文件地址
 */
export async function loadCss(src: string) {
  return new Promise<boolean>(resolve => {
    const linkElement = document.createElement("link");
    linkElement.rel = 'stylesheet';
    linkElement.href = src;
    linkElement.addEventListener('load', () => resolve(true));
    linkElement.addEventListener('error', () => resolve(false));
    document.head.append(linkElement);
  });
}
